<?php

namespace App\Models\Kms\Task;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;

class TaskNodesModel extends BaseModel
{
    use HasFactory;

    protected $table = "kms_task_nodes";

    protected $fillable = [
        "step",
        "businessStatus",
        "businessStatusText",
        "businessId",
        "businessType",
        "businessTypeText",
        "templateId",
        "status",
        "createdByUid",
        "taskId",
        "isApprovalRejected"
    ];

    const BUSINESS_STATUS_STAY     = 0;
    const BUSINESS_STATUS_FINISHED = 1;
    const BUSINESS_STATUS_REJECT   = 2;
    const BUSINESS_STATUS_INVALID  = 3;
    const BUSINESS_STATUS_TEXT     = [
        self::BUSINESS_STATUS_STAY     => "待完成",
        self::BUSINESS_STATUS_FINISHED => "已完成",
        self::BUSINESS_STATUS_REJECT   => "已驳回",
        self::BUSINESS_STATUS_INVALID  => "已废除",
    ];

    const STATUS_SELECTION = [
        self::BUSINESS_STATUS_FINISHED => "已完成/通过审批",
        self::BUSINESS_STATUS_REJECT   => "已驳回",
    ];

    const  IS_APPROVAL_REJECTED_YES  = 1;
    const  IS_APPROVAL_REJECTED_NO   = 0;
    const  IS_APPROVAL_REJECTED_TEXT = [
        self::IS_APPROVAL_REJECTED_YES => "驳回审批",
        self::IS_APPROVAL_REJECTED_NO  => "顺序审批"
    ];

    /**
     * @return HasMany
     */
    public function nodesProcessorRel(): HasMany
    {
        return $this->hasMany(TaskNodesProcessorModel::class, "nodeId", "id");
    }
}
